package ctrFinanceiro.gui.grid;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

import ctrFinanceiro.dmp.Conta;
import ctrFinanceiro.dmp.TipoCategoria;

public class CellRendererConta extends DefaultTableCellRenderer {

	private static final long serialVersionUID = 1L;

	public CellRendererConta() {
        super();        
    }
    
    public Color getCellColor(Conta conta){
        
        if(conta.getCategoria().getTipo().equals(TipoCategoria.C)) {
        	return Color.BLACK;
        }
        else if(conta.getCategoria().getTipo().equals(TipoCategoria.R)) {
        	return Color.BLUE;
        } else {
        	return Color.RED;
        }
    }
    
    public Component getTableCellRendererComponent(JTable table,
            Object value, boolean isSelected, boolean hasFocus, int row, int column){
        
        
        JLabel label = (JLabel)super.getTableCellRendererComponent(
                table, value, isSelected, hasFocus, row, column);
        
        Conta conta = ((TableModelConta)table.getModel()).getValues(row);

        label.setForeground(getCellColor(conta));
        
        if (column != 0)
            label.setHorizontalAlignment(JLabel.CENTER);
                
        
        if(column == 0 || column == 3)
        	label.setHorizontalAlignment(SwingConstants.CENTER);
        
        else if(column == 1 || column == 2)
        	label.setHorizontalAlignment(SwingConstants.LEFT);        
        
        else         
        	label.setHorizontalAlignment(SwingConstants.CENTER);
        	
        return label;
    }
    
}